﻿using Microsoft.AspNetCore.Mvc;

namespace Awesome.Controllers;

[ApiController]
[Route("api/[controller]")]
public class HomeController : ControllerBase {
  private readonly ILogger<HomeController> _logger;

  public HomeController (ILogger<HomeController> logger) {
    _logger = logger;
  }

  // http://localhost:8080/api/home/index/1
  [HttpGet("index/{id}")]
  public IActionResult Index (int id=1) {
    _logger.LogDebug("这是一条调试消息");
    _logger.LogInformation("这是一条提示消息");
    _logger.LogWarning("这是一条警告消息");
    _logger.LogError("这是一条错误消息");
    _logger.LogCritical("这是一条严重错误");
    return Ok($"【{id}】从构造函数解析依赖对象");
  }

  // http://localhost:8080/api/home/index2/1002
  [HttpGet("index2/{id}")]
  public IActionResult Index2 ([FromServices] ILogger<HomeController> _logger, int id =2) {
    _logger.LogError("我是从方法参数解析的ILogger对象");
    return Ok($"【{id}】从方法参数解析依赖对象");
  }

  // http://localhost:8080/api/home/index3/1003
  [HttpGet("index3/{id}")]
  public IActionResult Index3 (ILogger<HomeController> _logger, int id = 3) {
    _logger.LogError("我是从方法参数解析的ILogger对象");
    return Ok($"【{id}】从方法参数解析依赖对象");
  }
}